package com.etu.upload;

import java.util.HashMap;
import java.util.Map;

/**
 * 
 * @author xinyu126
 * */
public class Header implements HeaderImpl {
	//private String strHead;
	//private  String ContentType="";
	private Map<String,String> map;
	

	Header(){
		map=new HashMap<String,String>();
	}
	
	public void parse(String head){
		map.putAll(new ParameterParser().parse(head, new char[]{':','='}));
		
		//ContentType=
	}
	
	public String getFileName() {
		String filename=map.get("newfilename");
		if(filename!=null&&filename.length()>2){
			return filename;
		}
		return map.get("filename");
	}
	
	public String getFileType() {		
		String contentType=map.get("filetype");
		if(contentType!=null&&contentType.length()>2){
			return contentType;
		}
		contentType=map.get("Content-Type");
		if(contentType==null||contentType==""){
			contentType="UNKNOW-TYPE";
		}
		return contentType;
	}
	
	/**
	 * 将表单的file数据写入map
	 * @param String value;
	 * 取出map中的key=name的值作为key,将@param value作为value写入map
	 * */
	public void setValue(String value){
		String name=map.get("name");
		map.put(name, value);
	}
	
	/**
	 * @param String name;
	 * @return String value;
	 * */
	public String getValue(String name){
		return map.get(name);
	}

}
